package com.eatme.leetcode.problems;


public class Solution704 {

    public int search(int[] nums,int target) {
        return search(nums,0,nums.length-1, target);
    }

    public int search(int [] nums,int l,int r,int target) {
        if (l>r) return -1;
        int mid = l + (r-l) /2 ; // 避免整型溢出
        if (nums[mid]==target)
            return mid;
        if (nums[mid]<target)
            return  search(nums,mid+1,r,target);
        return search(nums,l,mid-1,target);
    }

    private static void main(String[] args) {
        int[] nums = {-1,0,3,5,9,12};
        int target = 9;
        int ret =new Solution704().search(nums,target);
        System.out.println(ret);
    }
}
